package com.yiwyn.advisordemo.advice;

import com.yiwyn.advisordemo.anno.Task;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.stereotype.Component;

@Component
public class TaskAdvice implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Task annotation = invocation.getMethod().getAnnotation(Task.class);
        System.out.println("方法调用前: " + invocation.getMethod().getName());
        Object result = invocation.proceed();
        System.out.println("方法调用后: " + invocation.getMethod().getName());
        return result;
    }
}